<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Pay as LibraryPay;
use app\common\model\User;

/**
 * 支付接口
 * 
 */
class Pay extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    /**
     * 支付
     * @ApiMethod (POST)
     * @param int $id  订单id
     * 
     */
    public function pay()
    {
        if (!$this->request->isPost()) {
            $this->error('提交类型错误');
        }
        $post = $this->request->post();
        $userInfo = User::get($this->auth->id);
        extract($post);
        if (!isset($id) || empty($id)) {
            $this->error('参数错误');
        }
        try {
            $data = LibraryPay::pay($id, $userInfo);
        } catch (\Exception $e) {
            $this->error('提交支付失败：' . $e->getMessage());
        }
        $this->success('', $data ?? '');
    }
}
